package com.yaocw.baseproject.fragment;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.yaocw.baseproject.R;
import com.yaocw.baseproject.adapter.HomeAdapter;
import com.yaocw.baseproject.entity.HomeEntity;

import java.util.ArrayList;

public class HomeFragment extends BaseFragment {

    private RecyclerView recyclerView;
    private RefreshLayout refreshLayout;
    private HomeAdapter homeAdapter;

    public static HomeFragment newInstance() {
        HomeFragment fragment = new HomeFragment();
        return fragment;
    }

    @Override
    protected int initLayout() {
        return R.layout.fragment_home;
    }

    @Override
    protected void initView() {
        recyclerView = mRootView.findViewById(R.id.recycler_view);
        refreshLayout = mRootView.findViewById(R.id.refresh_layout);
    }

    @Override
    protected void initData() {
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(linearLayoutManager);

        ArrayList<HomeEntity> bannerEntities = new ArrayList<HomeEntity>();
        bannerEntities.add(new HomeEntity(1));
        bannerEntities.add(new HomeEntity(2));
        bannerEntities.add(new HomeEntity(3));

        homeAdapter = new HomeAdapter(getActivity(), bannerEntities);
        recyclerView.setAdapter(homeAdapter);

        refreshLayout.setOnRefreshListener(refreshlayout -> {
            refreshLayout.finishRefresh();
        });

        refreshLayout.setOnLoadMoreListener(refreshlayout -> {
            refreshLayout.finishLoadMore();
        });
    }

}